<template>
  <div class="app-container">
    <search-box
      :fields="searchFeilds"
      @search="handleSearch"
      @add="handleAdd"
    />

    <SearchResult
      uid="newscenter"
      ref="searchResult"
      @edit="handleEdit"
      :ignoreCommand="ignoreCommand"
    >
      <el-table-column label="新闻标题" align="left">
        <template slot-scope="{row}">
          <span>{{ row.newTitle }}</span>
        </template>
      </el-table-column>

      <el-table-column label="浏览次数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.browseCount }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column label="新闻描述" align="center">
        <template slot-scope="{row}">
          <span>{{ row.newDescription }}</span>
        </template>
      </el-table-column>

      <el-table-column label="新闻内容" align="center">
        <template slot-scope="{row}">
          <span>{{ row.newContent }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="是否启用" align="center">
        <template slot-scope="{row}">
          <span>{{ isEnableMap[row.isEnable] }}</span>
        </template>
      </el-table-column>

      <el-table-column label="是否删除" align="center">
        <template slot-scope="{row}">
          <span>{{ isEnableMap[row.isDelete] }}</span>
        </template>
      </el-table-column>
    </SearchResult>
  </div>
</template>
<script>
import SearchBox from '@/components/SearchBox';
import SearchResult from '@/components/SearchResult';
import { isEnableOptions, isEnableMap } from '@/utils/config';

export default {
  name: 'news-center',
  components: { SearchBox, SearchResult },
  data() {
    return {
      searchFeilds: [
        { name: 'NewTitle', label: '新闻标题', type: 'text' },
        { name: 'NewDescription', label: '新闻描述', type: 'text' },
        { name: 'NewContent', label: '新闻内容', type: 'text' },
        { name: 'IsEnable', label: '是否启用', type: 'list', options: isEnableOptions },
        { name: 'IsDelete', label: '是否删除', type: 'list', options: isEnableOptions }
      ],
      ignoreCommand: ['detail'],
      isEnableMap
    };
  },
  methods: {
    // 搜索
    handleSearch(data) {
      if (data === void 0) data = {};

      this.$refs['searchResult'].getData(data);
    },

    handleAdd() {
      this.$store.dispatch({ type: 'news/setNewsMap', payload: {} });
      this.$router.push(`/news/create`);
    },

    // 编辑
    handleEdit(row) {
      this.$store.dispatch({ type: 'news/setNewsMap', payload: row });
      this.$router.push(`/news/edit`);
    }
  }
}
</script>
